package avicit.bdp.dgs.mdm.service;

import avicit.bdp.common.database.ColumnMeta;
import avicit.bdp.common.database.TableMeta;
import avicit.bdp.common.datasource.BaseDataSource;
import avicit.bdp.common.service.dto.DataSourceDTO;
import avicit.bdp.common.utils.VersionUtil;
import avicit.bdp.common.utils.database.DBUtils;
import avicit.bdp.common.utils.ConfigUtils;
import avicit.bdp.common.utils.database.adapter.DbAdapter;
import avicit.bdp.common.utils.database.adapter.DbAdapterUtils;
import avicit.bdp.dgs.mdm.dao.CodeDAO;
import avicit.bdp.dgs.mdm.dao.ColumnDAO;
import avicit.bdp.dgs.mdm.dao.TableDAO;
import avicit.bdp.dgs.mdm.dto.CodeDTO;
import avicit.bdp.dgs.mdm.dto.ColumnDTO;
import avicit.bdp.dgs.mdm.dto.TableDTO;
import avicit.bdp.dgs.mdm.utils.constants.Constants;
import avicit.bdp.dgs.mdm.utils.enums.ColumnInputType;
import avicit.bdp.dgs.mdm.utils.enums.DataState;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.commons.utils.StringUtils;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.exception.BusinessException;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

import static com.google.common.collect.Lists.newArrayList;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2023-12-11
 * @类说明：CommonService
 * @修改记录：
 * @注意事项：
 * @主要功能：公共服务Service
 */
@Service
public class CommonService {
    private static final Logger logger = LoggerFactory.getLogger(CommonService.class);

    @Autowired
    private TableDAO tableDAO;

    @Autowired
    private ColumnDAO columnDAO;

    @Autowired
    private CodeDAO codeDAO;

    /**
     * 获取系统默认字段
     *
     * @return
     */
    public List<ColumnDTO> getDefaultColumns() {
        List<ColumnDTO> defaultColumnList = newArrayList();

        // 模型ID
        ColumnDTO tableIdCol = new ColumnDTO();
        tableIdCol.setId(ComUtil.getId());
        tableIdCol.setName("sys_table_id");
        tableIdCol.setCnName("模型ID");
        tableIdCol.setColumnType("varchar");
        tableIdCol.setColumnLength(50);
        tableIdCol.setNullable(0);
        tableIdCol.setPrimaryKey(0);
        tableIdCol.setUniqueKey(0);
        defaultColumnList.add(tableIdCol);

        // 数据ID
        ColumnDTO dataIdCol = new ColumnDTO();
        dataIdCol.setId(ComUtil.getId());
        dataIdCol.setName("sys_data_id");
        dataIdCol.setCnName("数据ID");
        dataIdCol.setColumnType("varchar");
        dataIdCol.setColumnLength(50);
        dataIdCol.setNullable(0);
        dataIdCol.setPrimaryKey(0);
        dataIdCol.setUniqueKey(0);
        defaultColumnList.add(dataIdCol);

        // 版本状态
        ColumnDTO statusCol = new ColumnDTO();
        statusCol.setId(ComUtil.getId());
        statusCol.setName("sys_status");
        statusCol.setCnName("状态");
        statusCol.setColumnType("int");
        statusCol.setColumnLength(11);
        statusCol.setNullable(1);
        statusCol.setPrimaryKey(0);
        statusCol.setUniqueKey(0);
        defaultColumnList.add(statusCol);

        // 数据版本
        ColumnDTO dataVersionCol = new ColumnDTO();
        dataVersionCol.setId(ComUtil.getId());
        dataVersionCol.setName("sys_data_version");
        dataVersionCol.setCnName("数据版本");
        dataVersionCol.setColumnType("varchar");
        dataVersionCol.setColumnLength(50);
        dataVersionCol.setNullable(1);
        dataVersionCol.setPrimaryKey(0);
        dataVersionCol.setUniqueKey(0);
        defaultColumnList.add(dataVersionCol);

        // 创建人
        ColumnDTO createdByCol = new ColumnDTO();
        createdByCol.setId(ComUtil.getId());
        createdByCol.setName("sys_created_by");
        createdByCol.setCnName("创建人");
        createdByCol.setColumnType("varchar");
        createdByCol.setColumnLength(50);
        createdByCol.setNullable(1);
        createdByCol.setPrimaryKey(0);
        createdByCol.setUniqueKey(0);
        defaultColumnList.add(createdByCol);

        // 创建时间
        ColumnDTO creationDateCol = new ColumnDTO();
        creationDateCol.setId(ComUtil.getId());
        creationDateCol.setName("sys_creation_date");
        creationDateCol.setCnName("创建时间");
        creationDateCol.setColumnType("timestamp");
        creationDateCol.setColumnLength(0);
        creationDateCol.setNullable(1);
        creationDateCol.setPrimaryKey(0);
        creationDateCol.setUniqueKey(0);
        defaultColumnList.add(creationDateCol);

        // 更新人
        ColumnDTO lastUpdatedByCol = new ColumnDTO();
        lastUpdatedByCol.setId(ComUtil.getId());
        lastUpdatedByCol.setName("sys_last_updated_by");
        lastUpdatedByCol.setCnName("更新人");
        lastUpdatedByCol.setColumnType("varchar");
        lastUpdatedByCol.setColumnLength(50);
        lastUpdatedByCol.setNullable(1);
        lastUpdatedByCol.setPrimaryKey(0);
        lastUpdatedByCol.setUniqueKey(0);
        defaultColumnList.add(lastUpdatedByCol);

        // 更新时间
        ColumnDTO lastUpdateDateCol = new ColumnDTO();
        lastUpdateDateCol.setId(ComUtil.getId());
        lastUpdateDateCol.setName("sys_last_update_date");
        lastUpdateDateCol.setCnName("更新时间");
        lastUpdateDateCol.setColumnType("timestamp");
        lastUpdateDateCol.setColumnLength(0);
        lastUpdateDateCol.setNullable(1);
        lastUpdateDateCol.setPrimaryKey(0);
        lastUpdateDateCol.setUniqueKey(0);
        defaultColumnList.add(lastUpdateDateCol);

        // 组织机构
        ColumnDTO orgIdentityCol = new ColumnDTO();
        orgIdentityCol.setId(ComUtil.getId());
        orgIdentityCol.setName("sys_org_identity");
        orgIdentityCol.setCnName("组织机构");
        orgIdentityCol.setColumnType("varchar");
        orgIdentityCol.setColumnLength(32);
        orgIdentityCol.setNullable(1);
        orgIdentityCol.setPrimaryKey(0);
        orgIdentityCol.setUniqueKey(0);
        defaultColumnList.add(orgIdentityCol);

        // 密级
        ColumnDTO secretLevelCol = new ColumnDTO();
        secretLevelCol.setId(ComUtil.getId());
        secretLevelCol.setName("sys_secret_level");
        secretLevelCol.setCnName("密级");
        secretLevelCol.setColumnType("varchar");
        secretLevelCol.setColumnLength(32);
        secretLevelCol.setNullable(1);
        secretLevelCol.setPrimaryKey(0);
        secretLevelCol.setUniqueKey(0);
        defaultColumnList.add(secretLevelCol);

        return defaultColumnList;
    }

    /**
     * 根据主题ID获取模型信息
     *
     * @param topicId
     * @return
     */
    public TableDTO getTableByTopicId(String topicId) {
        if (StringUtils.isEmpty(topicId)) {
            throw new BusinessException("主题ID为空，获取模型失败");
        }
        List<TableDTO> queryRet = this.tableDAO.getModelByTopicId(topicId);
        if (CollectionUtils.isEmpty(queryRet)) {
            throw new BusinessException("未找到模型，主题ID：" + topicId);
        }

        return queryRet.get(0);
    }

    /**
     * 根据ID获取模型信息
     *
     * @param tableId
     * @return
     */
    public TableDTO getTableById(String tableId) {
        if (StringUtils.isEmpty(tableId)) {
            logger.warn("模型ID为空，获取模型失败");
            return null;
        }
        TableDTO queryRet = this.tableDAO.getModelDetail(tableId);
        if (queryRet == null) {
            logger.warn("未找到模型，id：" + tableId);
            return null;
        }

        return queryRet;
    }

    /**
     * 查询模型中字段列表
     *
     * @param tableId 模型ID
     * @return
     */
    public List<ColumnDTO> getColumnListByTableId(String tableId) {
        if (org.apache.commons.lang3.StringUtils.isEmpty(tableId)) {
            logger.warn("模型ID为空，获取字段列表失败.");
            return new ArrayList<>();
        }

        List<ColumnDTO> queryRet = this.columnDAO.getColumnListByCond(tableId);
        if (CollectionUtils.isEmpty(queryRet)) {
            logger.warn("未找到字段信息，tableId:" + tableId);
            return new ArrayList<>();
        }

        for (ColumnDTO column : queryRet) {
            column.setInputType(getColumnInputType(column.getColumnType()));
            column.setInputTypeName(ColumnInputType.getDescByCode(column.getInputType()));
        }

        return queryRet;
    }

    /**
     * 获取主数据默认数据源
     *
     * @return
     */
    public BaseDataSource getDefaultDataSource() {
        String dbType = ConfigUtils.getInstance().getString("mdm.storage.db.type", "mysql");
        String parameter = ConfigUtils.getInstance().getString("mdm.storage.db.parameter", null);

        DataSourceDTO dataSourceDTO = new DataSourceDTO();
        dataSourceDTO.setId(ComUtil.getId());
        dataSourceDTO.setDatasourceType(dbType);
        dataSourceDTO.setConnectionParams(parameter);

        return DBUtils.getBaseDataSource(dataSourceDTO);
    }

    /**
     * 获取数据库链接
     * 注意：
     * 1、临时方案，mdm存储信息直接配置公共参数列表中；
     * 2、最终方案：MDM管理->系统管理->存储配置，直接从公共数据源中引入数据源，仅一个数据源有效；
     *
     * @return
     */
    @SuppressWarnings("临时方案，后续优化")
    public Connection getConnect() {
        String dbType = ConfigUtils.getInstance().getString("mdm.storage.db.type", "mysql");
        String driverClass = ConfigUtils.getInstance().getString("mdm.storage.db.driverClass", "com.mysql.cj.jdbc.Driver");
        String url = ConfigUtils.getInstance().getString("mdm.storage.db.url", null);
        String username = ConfigUtils.getInstance().getString("mdm.storage.db.username", null);
        String password = ConfigUtils.getInstance().getString("mdm.storage.db.password", null);

        Properties prop = new Properties();
        prop.put("user", username);
        prop.put("password", password);
        try {
            Class.forName(driverClass);
            DriverManager.setLoginTimeout(15);
            return DriverManager.getConnection(url, prop);
        } catch (Exception e) {
            throw new BusinessException(String.format("链接数据失败,dbType=%s,user=%s, errMsg=%s", dbType, prop.getProperty("user"), e.getMessage()));
        }
    }

    /**
     * 获取主数据默认DB适配器
     *
     * @return
     */
    public DbAdapter getDefaultDbAdapter() {
        String dbType = ConfigUtils.getInstance().getString("mdm.storage.db.type", "mysql");

        return DbAdapterUtils.getDbAdapter(dbType);
    }

    /**
     * 创建新表
     *
     * @param tableDTO
     * @param columnList
     */
    public void createTable(TableDTO tableDTO, List<ColumnDTO> columnList) {
        // 拷贝表信息
        TableMeta tableMeta = new TableMeta();
        BeanUtils.copyProperties(tableDTO, tableMeta);
        tableMeta.setCnName(tableDTO.getName());
        tableMeta.setName(tableDTO.getTableName());

        // 拷贝字段信息
        List<ColumnMeta> columnMetaList = newArrayList();
        columnList.addAll(getDefaultColumns());
        for (ColumnDTO column : columnList) {
            ColumnMeta columnMeta = new ColumnMeta();
            BeanUtils.copyProperties(column, columnMeta);
            columnMetaList.add(columnMeta);
        }
        tableMeta.setColumnMetaData(columnMetaList);

        try {
            String dbType = ConfigUtils.getInstance().getString("mdm.storage.db.type", "mysql");
            DbAdapter adapter = DbAdapterUtils.getDbAdapter(dbType);
            adapter.createDataTable(tableMeta, getConnect());
        } catch (Exception e) {
            logger.error("创建表[{}]失败,errMsg", tableDTO.getTableName(), e.getMessage());
            throw new BusinessException("创建表失败", e);
        }
    }

    /**
     * 执行SQL
     *
     * @param sql
     */
    public void executeSql(String sql) {
        PreparedStatement state = null;
        try {
            logger.info("开始执行SQL：" + sql);
            state = getConnect().prepareStatement(sql);
            state.execute();
            logger.info("结束执行SQL：" + sql);
        } catch (Exception e) {
            throw new BusinessException(e.getMessage());
        } finally {
            DBUtils.closeResource(null, state, null);
        }
    }

    /**
     * 删除表
     *
     * @param sql
     * @param tableName
     */
    @SuppressWarnings("临时方案，后续直接DbAdapter.dropTable接口")
    public void dropTable(String tableName, String sql) {
        logger.info("删除对应的数据表[{}]开始。", tableName);
        executeSql(sql);
        logger.info("删除对应的数据表[{}]结束。", tableName);
    }

    /**
     * 插入数据湖
     *
     * @param tableName
     * @param sql
     */
    public void insertTable(String tableName, String sql) {
        logger.info("向数据表[{}]添加数据开始。", tableName);
        executeSql(sql);
        logger.info("向数据表[{}]添加数据结束。", tableName);
    }

    /**
     * 更新数据
     *
     * @param tableName
     * @param sql
     */
    public void updateTable(String tableName, String sql) {
        logger.info("向数据表[{}]更新数据开始。", tableName);
        executeSql(sql);
        logger.info("向数据表[{}]更新数据结束。", tableName);
    }

    /**
     * 删除数据
     *
     * @param tableName
     * @param sql
     */
    public void deleteData(String tableName, String sql) {
        logger.info("删除数据表[{}]中数据开始。", tableName);
        executeSql(sql);
        logger.info("删除数据表[{}]中数据结束。", tableName);
    }

    /**
     * 获取删除表SQL
     *
     * @param tableName
     * @return
     */
    public String getDropTableSql(String tableName) {
        return "DROP TABLE IF EXISTS " + tableName;
    }

    /**
     * 获取查询数据SQL
     *
     * @param tableName
     * @param dataId
     * @param columnList
     * @return
     */
    public String getQuerySql(String tableName, String dataId, List<ColumnDTO> columnList) {
        if (StringUtils.isEmpty(tableName)) {
            throw new BusinessException("模型表名称为空，获取查询数据SQL失败");
        }
        if (CollectionUtils.isEmpty(columnList)) {
            throw new BusinessException("字段列表为空，获取查询数据SQL失败");
        }

        List<String> nameList = columnList.stream().map(ColumnDTO::getName).collect(Collectors.toList());
        StringBuilder sqlSb = new StringBuilder();
        sqlSb.append("select ").append(String.join(",", nameList)).append(" from ").append(tableName);
        if (StringUtils.isNotEmpty(dataId)) {
            sqlSb.append(" where sys_data_id=").append("'").append(dataId).append("'");
        }

        return sqlSb.toString();
    }

    /**
     * 构建Insert SQL
     *
     * @param tableId    模型ID
     * @param dataId     数据ID
     * @param tableName  表名称
     * @param dataList   数据列表
     * @param columnList 字段列表
     * @return
     */
    public String getInsertSql(String tableId, String dataId, String tableName, Map<String, Object> dataList, List<ColumnDTO> columnList) {
        // step1:初始化
        // 组织机构ID
        String orgId = ThreadContextHelper.getOrgId();
        // 数据状态
        Integer dataStatus = DataState.EDIT.getCode();
        // 创建人，默认平台管理员
        String createdBy = ThreadContextHelper.getUserId() == null ? "1" : ThreadContextHelper.getUserId();
        // 创建时间
        String creationDate = new Timestamp(System.currentTimeMillis()).toString();
        // 更新人
        String lastUpdatedBy = ThreadContextHelper.getUserId() == null ? "1" : ThreadContextHelper.getUserId();
        // 更新时间
        String lastUpdateDate = new Timestamp(System.currentTimeMillis()).toString();

        Map<String, ColumnDTO> columnMap = columnList.stream().collect(Collectors.toMap(ColumnDTO::getName, item -> item));

        // step2；构建Insert SQL
        StringBuilder metadataSb = new StringBuilder();
        StringBuilder dataSb = new StringBuilder();
        // 结果表名称
        metadataSb.append("INSERT INTO ").append(tableName).append("(");
        dataSb.append(" VALUES(");

        for (Map.Entry<String, Object> data : dataList.entrySet()) {
            String columnName = data.getKey();
            Object value = data.getValue();
            if (StringUtils.isEmpty(columnName) || value == null) {
                continue;
            }

            ColumnDTO columnDTO = columnMap.get(columnName);
            if (columnDTO == null) {
                continue;
            }

            String columnType = columnDTO.getColumnType();
            if (isNeedAddSingleQuotationMarks(columnType)) {
                dataSb.append("'").append(value).append("'").append(",");
            } else {
                dataSb.append(value).append(",");
            }

            metadataSb.append(columnName).append(",");
        }

        // 模型ID
        metadataSb.append("sys_table_id").append(",");
        dataSb.append("'").append(tableId).append("'").append(",");

        // 数据ID
        metadataSb.append("sys_data_id").append(",");
        dataSb.append("'").append(dataId).append("'").append(",");

        // 数据状态
        metadataSb.append("sys_status").append(",");
        dataSb.append(dataStatus).append(",");

        // 创建人
        metadataSb.append("sys_created_by").append(",");
        dataSb.append("'").append(createdBy).append("'").append(",");

        // 创建时间
        metadataSb.append("sys_creation_date").append(",");
        dataSb.append("'").append(creationDate).append("'").append(",");

        // 更新人
        metadataSb.append("sys_last_updated_by").append(",");
        dataSb.append("'").append(lastUpdatedBy).append("'").append(",");

        // 更新时间
        metadataSb.append("sys_last_update_date").append(",");
        dataSb.append("'").append(lastUpdateDate).append("'").append(",");

        // 组织机构
        metadataSb.append("sys_org_identity");
        dataSb.append("'").append(orgId).append("'");

        metadataSb.append(") ");
        dataSb.append(")");

        return metadataSb.append(dataSb.toString()).toString();
    }

    /**
     * 构建Update SQL
     *
     * @param dataId     数据ID
     * @param tableName  表名称
     * @param dataList   数据列表
     * @param columnList 字段列表
     * @return
     */
    public String getUpdateSql(String dataId, String tableName, Map<String, Object> dataList, List<ColumnDTO> columnList) {
        // step1:初始化
        // 更新人
        String lastUpdatedBy = ThreadContextHelper.getUserId() == null ? "1" : ThreadContextHelper.getUserId();
        // 更新时间
        String lastUpdateDate = new Timestamp(System.currentTimeMillis()).toString();

        // step2；构建Update SQL
        Map<String, ColumnDTO> columnMap = columnList.stream().collect(Collectors.toMap(ColumnDTO::getName, item -> item));
        StringBuilder sqlSb = new StringBuilder();
        // 结果表名称
        sqlSb.append("UPDATE ").append(tableName).append(" SET ");

        for (Map.Entry<String, Object> data : dataList.entrySet()) {
            String columnName = data.getKey();
            Object value = data.getValue();
            if (StringUtils.isEmpty(columnName) || value == null) {
                continue;
            }

            ColumnDTO columnDTO = columnMap.get(columnName);
            if (columnDTO == null) {
                continue;
            }

            String columnType = columnDTO.getColumnType();
            if (isNeedAddSingleQuotationMarks(columnType)) {
                sqlSb.append(columnName).append("=").append("'").append(value).append("'").append(",");
            } else {
                sqlSb.append(columnName).append("=").append(value).append(",");
            }
        }

        // 更新人
        sqlSb.append("sys_last_updated_by").append("=").append("'").append(lastUpdatedBy).append("'").append(",");

        // 更新时间
        sqlSb.append("sys_last_update_date").append("=").append("'").append(lastUpdateDate).append("'");

        // where条件
        sqlSb.append(" where sys_data_id=").append("'").append(dataId).append("'");

        return sqlSb.toString();
    }

    /**
     * 获取删除数据SQL
     *
     * @param tableName
     * @param dataId
     * @return
     */
    public String getDeleteTableSql(String tableName, String dataId) {
        return "DELETE FROM " + tableName + " where sys_data_id = " + String.format("'%s'", dataId);
    }

    /**
     * 获取更新数据状态SQL
     *
     * @param tableName
     * @param dataId
     * @param status
     * @param oldVersion
     * @return
     */
    public String getUpdateStatusSql(String tableName, String dataId, Integer status, String oldVersion) {
        StringBuilder sqlSb = new StringBuilder();

        if (DataState.EFFECTIVE.getCode() == status) {
            sqlSb.append("UPDATE ").append(tableName)
                    .append(" SET")
                    .append(" sys_data_version=").append("'").append(getNextVersion(oldVersion)).append("'").append(",")
                    .append(" sys_status=").append(status).append(",")
                    .append(" sys_last_updated_by=").append("'").append(ThreadContextHelper.getUserId() == null ? "1" : ThreadContextHelper.getUserId()).append("'").append(",")
                    .append(" sys_last_update_date=").append("'").append(new Timestamp(System.currentTimeMillis()).toString()).append("'")
                    .append(" WHERE ").append("sys_data_id=").append("'").append(dataId).append("'");
        } else {
            sqlSb.append("UPDATE ").append(tableName)
                    .append(" SET")
                    .append(" sys_status=").append(status).append(",")
                    .append(" sys_last_updated_by=").append("'").append(ThreadContextHelper.getUserId() == null ? "1" : ThreadContextHelper.getUserId()).append("'").append(",")
                    .append(" sys_last_update_date=").append("'").append(new Timestamp(System.currentTimeMillis()).toString()).append("'")
                    .append(" WHERE ").append("sys_data_id=").append("'").append(dataId).append("'");
        }

        return sqlSb.toString();
    }

    /**
     * 根据条件获取编码列表
     *
     * @param tableId
     * @return
     */
    public List<CodeDTO> getCodeListByCond(String tableId) {
        if (StringUtils.isEmpty(tableId)) {
            logger.warn("模型ID为空，获取编码列表失败");
            return new ArrayList<>();
        }

        return this.codeDAO.getCodeListByCond(tableId);
    }

    /**
     * 根据模型ID删除字段信息
     *
     * @param tableId
     * @return
     */
    public int deleteColumnByTableId(String tableId) {
        // 删除字段编码规则
        this.codeDAO.deleteCodeByCond(null, null, tableId);

        // 删除字段
        return this.columnDAO.deleteColumnByCond(null, tableId);
    }

    /**
     * 根据字段ID删除编码规则
     *
     * @param columnId
     * @param tableId
     * @return
     */
    public int deleteCodeByCond(String columnId, String tableId) {
        return this.codeDAO.deleteCodeByCond(null, columnId, tableId);
    }

    /**
     * 判断字段类型是否为字符型，包括字符、时间等，如果是需要加单引号
     *
     * @param columnType
     * @return
     */
    private boolean isNeedAddSingleQuotationMarks(String columnType) {
        switch (columnType) {
            case "char":
            case "varchar":
            case "text":
            case "mediumtext":
            case "longtext":
            case "blob":
            case "date":
            case "time":
            case "year":
            case "datetime":
            case "timestamp":
                return true;
            default:
                return false;
        }
    }

    /**
     * 根据字段类型获取输入类型
     *
     * @param columnType
     * @return
     */
    private int getColumnInputType(String columnType) {
        switch (columnType) {
            case "char":
            case "varchar":
            case "text":
            case "mediumtext":
            case "longtext":
            case "blob":
                return ColumnInputType.INPUT.getCode();
            case "date":
            case "time":
            case "year":
            case "datetime":
            case "timestamp":
                return ColumnInputType.DATE_PICKER.getCode();
            case "tinyint":
            case "smallint":
            case "mediumint":
            case "int":
            case "integer":
            case "bigint":
            case "float":
            case "double":
            case "decimal":
                return ColumnInputType.INPUT_NUM.getCode();
            default:
                return ColumnInputType.INPUT.getCode();
        }
    }

    /**
     * 获取版本信息
     * 注意：版本v1.0，下一个版本v1.1
     *
     * @param oldVersion
     * @return
     */
    private String getNextVersion(String oldVersion) {
        if (org.apache.commons.lang3.StringUtils.isEmpty(oldVersion)) {
            return Constants.VERSION_PREFIX + VersionUtil.generateVersion2Default();
        }

        String nextVersion = VersionUtil.generateVersion2Next(oldVersion.substring(1));
        return Constants.VERSION_PREFIX + nextVersion;
    }
}
